package com.books.config;

/**
 * @author ZhouRui
 * @title: 码上就来
 * @projectName cbstore-spring-boot
 * @description: TODO
 * @date 2021/10/3014:18
 */


import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryNTimes;
import org.apache.mahout.cf.taste.impl.model.jdbc.MySQLJDBCDataModel;

import org.apache.mahout.cf.taste.model.DataModel;
import org.apache.mahout.cf.taste.model.JDBCDataModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;


@Configuration
public class MyConfig {

    @Autowired(required = false)
    private DataSource dataSource;

    @Bean
    public DataModel getMySQLDataModel(){
        //参数1：mysql数据源信息，参数2：表名，参数3：用户列字段，参数4：商品列字段，参数5：偏好值字段，参数6：时间戳
        JDBCDataModel dataModel=new MySQLJDBCDataModel(dataSource,"user_pianhao_data1","uid","pid","val", "time");
        return dataModel;
    }
    @Bean
    public CuratorFramework curatorFramework() {
        return CuratorFrameworkFactory.newClient("47.100.102.177:2181", new RetryNTimes(5, 1000));
    }
}
